package auth

import (
	"fmt"
	"github.com/golang-jwt/jwt/v4"
)

func ParesToken(tokenString string) (*CustomClaims, error) {
	token, err := jwt.ParseWithClaims(tokenString, &CustomClaims{}, func(token *jwt.Token) (interface{}, error) {
		return []byte(pSecretKey), nil
	})
	if err != nil {
		fmt.Printf("token parse error: %v\n", err)
		return nil, err
	}
	claims, ok := token.Claims.(*CustomClaims)
	if !ok || !token.Valid {
		return nil, err
	}
	return claims, nil
}
